//--------------------------------------------------------------------------
// 
//  Copyright (c) Chili Software.  All rights reserved. 
// 
//  File: MsSqlSubTransaction.cs
//
//  Description: Provides a transaction object for sub transactions.
// 
//--------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;

namespace Chili.Opf3.Storages.MsSql
{
	/// <summary>
	/// Class that provides a sub transaction object for the <see cref="MsSqlStorage">MsSqlStorage</see> class.
	/// </summary>
	/// <remarks>
	/// This class provides a sub transaction object for the <see cref="MsSqlStorage">MsSqlStorage</see> class.
	/// It is returned by the <see cref="MsSqlStorage.StartTransaction">StartTransaction</see> methods of 
	/// the class.
	/// </remarks>
	internal sealed class MsSqlSubTransaction : MsSqlTransaction
	{
		private bool _active = true;

		/// <summary>
		/// Creates a new instance of the <see cref="MsSqlSubTransaction">MsSqlSubTransaction Class</see>.
		/// </summary>
		/// <param name="transaction"></param>
		internal MsSqlSubTransaction(SqlTransaction transaction)
			: base(transaction)
		{
		}

		#region Overridden Members

		/// <summary>
		/// Rolls the current transaction back.
		/// </summary>
		public override void Rollback()
		{
			// Roll back to the root of this sub transaction.
			Rollback(this.Root);

			_active = false;
		}

		/// <summary>
		/// Commits the current transaction.
		/// </summary>
		public override void Commit()
		{
			_active = false;
			// Nothing to do here.
		}

		/// <summary>
		/// Returns whether the transaction is active.
		/// </summary>
		public override bool Active
		{
			get
			{
				return _active;
			}
		}

		#endregion
	}
}
